{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "8a1f6604",
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "import pandas as pd\n",
    "import numpy as np \n",
    "import pandas as pd\n",
    "from tqdm.notebook import tqdm\n",
    "\n",
    "path_root = '../input/optiver-realized-volatility-prediction'\n",
    "path_data = '../input/optiver-realized-volatility-prediction'\n",
    "path_submissions = '/'\n",
    "\n",
    "target_name = 'target'\n",
    "scores_folds = {}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "3ea8b11a",
   "metadata": {},
   "outputs": [],
   "source": [
    "def log_return(list_stock_prices):\n",
    "    return np.log(list_stock_prices).diff() \n",
    "\n",
    "def realized_volatility(series_log_return):\n",
    "    return np.sqrt(np.sum(series_log_return**2))\n",
    "\n",
    "def rmspe(y_true, y_pred):\n",
    "    return  (np.sqrt(np.mean(np.square((y_true - y_pred) / y_true))))\n",
    "\n",
    "def calc_wap1(df):\n",
    "    wap = (df['bid_price1'] * df['ask_size1'] + df['ask_price1'] * df['bid_size1']) / (df['bid_size1'] + df['ask_size1'])\n",
    "    return wap\n",
    "\n",
    "def calc_wap2(df):\n",
    "    wap = (df['bid_price2'] * df['ask_size2'] + df['ask_price2'] * df['bid_size2']) / (df['bid_size2'] + df['ask_size2'])\n",
    "    return wap"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "bb8629b0",
   "metadata": {},
   "outputs": [],
   "source": [
    "train = pd.read_csv(os.path.join(path_data, 'train.csv'))\n",
    "all_stock_ids = train['stock_id'].unique()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "34ad8195",
   "metadata": {},
   "outputs": [],
   "source": [
    "dataType = 'train'\n",
    "stock_id = 11\n",
    "df = pd.read_parquet(os.path.join(path_data, 'book_{}.parquet/stock_id={}/'.format(dataType, stock_id)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "ed59fe09",
   "metadata": {},
   "outputs": [],
   "source": [
    "df['wap1'] = (df['bid_price1'] * df['ask_size1'] + df['ask_price1'] * df['bid_size1']) / (df['bid_size1'] + df['ask_size1'])\n",
    "df['wap2'] = (df['bid_price2'] * df['ask_size2'] + df['ask_price2'] * df['bid_size2']) / (df['bid_size2'] + df['ask_size2'])\n",
    "df['log_return1'] = df.groupby(['time_id'])['wap1'].apply(log_return).fillna(0)\n",
    "df['log_return2'] = df.groupby(['time_id'])['wap2'].apply(log_return).fillna(0)\n",
    "df['wap_balance'] = abs(df['wap1'] - df['wap2'])\n",
    "df['price_spread'] = (df['ask_price1'] - df['bid_price1']) / ((df['ask_price1'] + df['bid_price1']) / 2)\n",
    "df['price_spread2'] = (df['ask_price2'] - df['bid_price2']) / ((df['ask_price2'] + df['bid_price2']) / 2)\n",
    "df['bid_spread'] = df['bid_price1'] - df['bid_price2']\n",
    "df['ask_spread'] = df['ask_price1'] - df['ask_price2']\n",
    "df[\"bid_ask_spread\"] = abs(df['bid_spread'] - df['ask_spread'])\n",
    "df['total_volume'] = (df['ask_size1'] + df['ask_size2']) + (df['bid_size1'] + df['bid_size2'])\n",
    "df['volume_imbalance'] = abs((df['ask_size1'] + df['ask_size2']) - (df['bid_size1'] + df['bid_size2']))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "b4facfc1",
   "metadata": {},
   "outputs": [],
   "source": [
    "create_feature_dict = {\n",
    "        'wap1': [np.sum, np.mean, np.std],\n",
    "        'wap2': [np.sum, np.mean, np.std],\n",
    "        'log_return1': [np.sum, realized_volatility, np.mean, np.std],\n",
    "        'log_return2': [np.sum, realized_volatility, np.mean, np.std],\n",
    "        'wap_balance': [np.sum, np.mean, np.std],\n",
    "        'price_spread':[np.sum, np.mean, np.std],\n",
    "        'price_spread2':[np.sum, np.mean, np.std],\n",
    "        'bid_spread':[np.sum, np.mean, np.std],\n",
    "        'ask_spread':[np.sum, np.mean, np.std],\n",
    "        'total_volume':[np.sum, np.mean, np.std],\n",
    "        'volume_imbalance':[np.sum, np.mean, np.std],\n",
    "        \"bid_ask_spread\":[np.sum, np.mean, np.std],\n",
    "    }\n",
    "\n",
    "def get_stats_window(seconds_in_bucket, add_suffix = False):\n",
    "    # Group by the window\n",
    "    df_feature = df[df['seconds_in_bucket'] >= seconds_in_bucket].groupby(['time_id']).agg(create_feature_dict).reset_index()\n",
    "    # Rename columns joining suffix\n",
    "    df_feature.columns = ['_'.join(col) for col in df_feature.columns]\n",
    "    # Add a suffix to differentiate windows\n",
    "    if add_suffix:\n",
    "        df_feature = df_feature.add_suffix('_' + str(seconds_in_bucket))\n",
    "    return df_feature"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "e4bb6eb2",
   "metadata": {},
   "outputs": [],
   "source": [
    "df_feature = get_stats_window(seconds_in_bucket = 0, add_suffix = False)\n",
    "df_feature_400 = get_stats_window(seconds_in_bucket = 400, add_suffix = True)\n",
    "df_feature_300 = get_stats_window(seconds_in_bucket = 300, add_suffix = True)\n",
    "df_feature_200 = get_stats_window(seconds_in_bucket = 200, add_suffix = True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "9482bd5f",
   "metadata": {},
   "outputs": [],
   "source": [
    "df_feature = df_feature.merge(df_feature_400, how = 'left', left_on = 'time_id_', right_on = 'time_id__400')\n",
    "df_feature = df_feature.merge(df_feature_300, how = 'left', left_on = 'time_id_', right_on = 'time_id__300')\n",
    "df_feature = df_feature.merge(df_feature_200, how = 'left', left_on = 'time_id_', right_on = 'time_id__200')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "6310ed12",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>time_id_</th>\n",
       "      <th>wap1_sum</th>\n",
       "      <th>wap1_mean</th>\n",
       "      <th>wap1_std</th>\n",
       "      <th>wap2_sum</th>\n",
       "      <th>wap2_mean</th>\n",
       "      <th>wap2_std</th>\n",
       "      <th>log_return1_sum</th>\n",
       "      <th>log_return1_realized_volatility</th>\n",
       "      <th>log_return1_mean</th>\n",
       "      <th>...</th>\n",
       "      <th>ask_spread_std_200</th>\n",
       "      <th>total_volume_sum_200</th>\n",
       "      <th>total_volume_mean_200</th>\n",
       "      <th>total_volume_std_200</th>\n",
       "      <th>volume_imbalance_sum_200</th>\n",
       "      <th>volume_imbalance_mean_200</th>\n",
       "      <th>volume_imbalance_std_200</th>\n",
       "      <th>bid_ask_spread_sum_200</th>\n",
       "      <th>bid_ask_spread_mean_200</th>\n",
       "      <th>bid_ask_spread_std_200</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>5</td>\n",
       "      <td>383.280548</td>\n",
       "      <td>1.003352</td>\n",
       "      <td>0.000954</td>\n",
       "      <td>383.373383</td>\n",
       "      <td>1.003595</td>\n",
       "      <td>0.001099</td>\n",
       "      <td>0.000284</td>\n",
       "      <td>0.008127</td>\n",
       "      <td>7.439834e-07</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000241</td>\n",
       "      <td>122405</td>\n",
       "      <td>493.568548</td>\n",
       "      <td>297.528230</td>\n",
       "      <td>47083</td>\n",
       "      <td>189.850806</td>\n",
       "      <td>169.815588</td>\n",
       "      <td>0.117340</td>\n",
       "      <td>0.000473</td>\n",
       "      <td>0.000345</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>11</td>\n",
       "      <td>232.981049</td>\n",
       "      <td>0.999919</td>\n",
       "      <td>0.000237</td>\n",
       "      <td>232.998032</td>\n",
       "      <td>0.999992</td>\n",
       "      <td>0.000357</td>\n",
       "      <td>0.000132</td>\n",
       "      <td>0.002388</td>\n",
       "      <td>5.663181e-07</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000103</td>\n",
       "      <td>75119</td>\n",
       "      <td>552.345588</td>\n",
       "      <td>405.412262</td>\n",
       "      <td>44587</td>\n",
       "      <td>327.845588</td>\n",
       "      <td>343.032789</td>\n",
       "      <td>0.035497</td>\n",
       "      <td>0.000261</td>\n",
       "      <td>0.000118</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>16</td>\n",
       "      <td>306.656372</td>\n",
       "      <td>1.002145</td>\n",
       "      <td>0.000945</td>\n",
       "      <td>306.649689</td>\n",
       "      <td>1.002123</td>\n",
       "      <td>0.000951</td>\n",
       "      <td>-0.000196</td>\n",
       "      <td>0.004095</td>\n",
       "      <td>-6.390906e-07</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000077</td>\n",
       "      <td>89891</td>\n",
       "      <td>478.143617</td>\n",
       "      <td>176.620308</td>\n",
       "      <td>28631</td>\n",
       "      <td>152.292553</td>\n",
       "      <td>118.542551</td>\n",
       "      <td>0.061287</td>\n",
       "      <td>0.000326</td>\n",
       "      <td>0.000144</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>31</td>\n",
       "      <td>215.024139</td>\n",
       "      <td>1.000112</td>\n",
       "      <td>0.000660</td>\n",
       "      <td>215.021683</td>\n",
       "      <td>1.000101</td>\n",
       "      <td>0.000610</td>\n",
       "      <td>0.000355</td>\n",
       "      <td>0.003855</td>\n",
       "      <td>1.649800e-06</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000191</td>\n",
       "      <td>89760</td>\n",
       "      <td>655.182482</td>\n",
       "      <td>239.083336</td>\n",
       "      <td>30554</td>\n",
       "      <td>223.021898</td>\n",
       "      <td>135.579663</td>\n",
       "      <td>0.052588</td>\n",
       "      <td>0.000384</td>\n",
       "      <td>0.000293</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>62</td>\n",
       "      <td>158.910904</td>\n",
       "      <td>0.999440</td>\n",
       "      <td>0.000575</td>\n",
       "      <td>158.909622</td>\n",
       "      <td>0.999432</td>\n",
       "      <td>0.000583</td>\n",
       "      <td>-0.000217</td>\n",
       "      <td>0.002140</td>\n",
       "      <td>-1.363065e-06</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000141</td>\n",
       "      <td>68082</td>\n",
       "      <td>660.990291</td>\n",
       "      <td>266.432403</td>\n",
       "      <td>18912</td>\n",
       "      <td>183.611650</td>\n",
       "      <td>139.040143</td>\n",
       "      <td>0.030120</td>\n",
       "      <td>0.000292</td>\n",
       "      <td>0.000147</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3825</th>\n",
       "      <td>32751</td>\n",
       "      <td>444.130219</td>\n",
       "      <td>1.000293</td>\n",
       "      <td>0.000244</td>\n",
       "      <td>444.122772</td>\n",
       "      <td>1.000276</td>\n",
       "      <td>0.000303</td>\n",
       "      <td>-0.000746</td>\n",
       "      <td>0.002631</td>\n",
       "      <td>-1.680385e-06</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000113</td>\n",
       "      <td>178047</td>\n",
       "      <td>599.484848</td>\n",
       "      <td>262.821400</td>\n",
       "      <td>91979</td>\n",
       "      <td>309.693603</td>\n",
       "      <td>215.491277</td>\n",
       "      <td>0.073425</td>\n",
       "      <td>0.000247</td>\n",
       "      <td>0.000127</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3826</th>\n",
       "      <td>32753</td>\n",
       "      <td>303.743774</td>\n",
       "      <td>1.002455</td>\n",
       "      <td>0.001758</td>\n",
       "      <td>303.755768</td>\n",
       "      <td>1.002494</td>\n",
       "      <td>0.001848</td>\n",
       "      <td>0.006023</td>\n",
       "      <td>0.004174</td>\n",
       "      <td>1.987797e-05</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000181</td>\n",
       "      <td>232913</td>\n",
       "      <td>1088.378505</td>\n",
       "      <td>736.848563</td>\n",
       "      <td>113855</td>\n",
       "      <td>532.032710</td>\n",
       "      <td>689.228523</td>\n",
       "      <td>0.090269</td>\n",
       "      <td>0.000422</td>\n",
       "      <td>0.000269</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3827</th>\n",
       "      <td>32758</td>\n",
       "      <td>254.079773</td>\n",
       "      <td>1.000314</td>\n",
       "      <td>0.000519</td>\n",
       "      <td>254.066162</td>\n",
       "      <td>1.000260</td>\n",
       "      <td>0.000540</td>\n",
       "      <td>0.000989</td>\n",
       "      <td>0.002493</td>\n",
       "      <td>3.893041e-06</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000062</td>\n",
       "      <td>105003</td>\n",
       "      <td>656.268750</td>\n",
       "      <td>197.565138</td>\n",
       "      <td>22315</td>\n",
       "      <td>139.468750</td>\n",
       "      <td>123.093048</td>\n",
       "      <td>0.038521</td>\n",
       "      <td>0.000241</td>\n",
       "      <td>0.000128</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3828</th>\n",
       "      <td>32763</td>\n",
       "      <td>463.937042</td>\n",
       "      <td>1.004193</td>\n",
       "      <td>0.002389</td>\n",
       "      <td>463.931610</td>\n",
       "      <td>1.004181</td>\n",
       "      <td>0.002396</td>\n",
       "      <td>0.006534</td>\n",
       "      <td>0.003792</td>\n",
       "      <td>1.414297e-05</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000059</td>\n",
       "      <td>200949</td>\n",
       "      <td>654.557003</td>\n",
       "      <td>304.005481</td>\n",
       "      <td>61415</td>\n",
       "      <td>200.048860</td>\n",
       "      <td>204.854917</td>\n",
       "      <td>0.089613</td>\n",
       "      <td>0.000292</td>\n",
       "      <td>0.000119</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3829</th>\n",
       "      <td>32767</td>\n",
       "      <td>366.562225</td>\n",
       "      <td>1.001536</td>\n",
       "      <td>0.001232</td>\n",
       "      <td>366.560822</td>\n",
       "      <td>1.001532</td>\n",
       "      <td>0.001274</td>\n",
       "      <td>0.002419</td>\n",
       "      <td>0.002867</td>\n",
       "      <td>6.609636e-06</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000095</td>\n",
       "      <td>165538</td>\n",
       "      <td>710.463519</td>\n",
       "      <td>236.864722</td>\n",
       "      <td>44448</td>\n",
       "      <td>190.763948</td>\n",
       "      <td>166.924126</td>\n",
       "      <td>0.067559</td>\n",
       "      <td>0.000290</td>\n",
       "      <td>0.000118</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>3830 rows × 156 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "      time_id_    wap1_sum  wap1_mean  wap1_std    wap2_sum  wap2_mean  \\\n",
       "0            5  383.280548   1.003352  0.000954  383.373383   1.003595   \n",
       "1           11  232.981049   0.999919  0.000237  232.998032   0.999992   \n",
       "2           16  306.656372   1.002145  0.000945  306.649689   1.002123   \n",
       "3           31  215.024139   1.000112  0.000660  215.021683   1.000101   \n",
       "4           62  158.910904   0.999440  0.000575  158.909622   0.999432   \n",
       "...        ...         ...        ...       ...         ...        ...   \n",
       "3825     32751  444.130219   1.000293  0.000244  444.122772   1.000276   \n",
       "3826     32753  303.743774   1.002455  0.001758  303.755768   1.002494   \n",
       "3827     32758  254.079773   1.000314  0.000519  254.066162   1.000260   \n",
       "3828     32763  463.937042   1.004193  0.002389  463.931610   1.004181   \n",
       "3829     32767  366.562225   1.001536  0.001232  366.560822   1.001532   \n",
       "\n",
       "      wap2_std  log_return1_sum  log_return1_realized_volatility  \\\n",
       "0     0.001099         0.000284                         0.008127   \n",
       "1     0.000357         0.000132                         0.002388   \n",
       "2     0.000951        -0.000196                         0.004095   \n",
       "3     0.000610         0.000355                         0.003855   \n",
       "4     0.000583        -0.000217                         0.002140   \n",
       "...        ...              ...                              ...   \n",
       "3825  0.000303        -0.000746                         0.002631   \n",
       "3826  0.001848         0.006023                         0.004174   \n",
       "3827  0.000540         0.000989                         0.002493   \n",
       "3828  0.002396         0.006534                         0.003792   \n",
       "3829  0.001274         0.002419                         0.002867   \n",
       "\n",
       "      log_return1_mean  ...  ask_spread_std_200  total_volume_sum_200  \\\n",
       "0         7.439834e-07  ...            0.000241                122405   \n",
       "1         5.663181e-07  ...            0.000103                 75119   \n",
       "2        -6.390906e-07  ...            0.000077                 89891   \n",
       "3         1.649800e-06  ...            0.000191                 89760   \n",
       "4        -1.363065e-06  ...            0.000141                 68082   \n",
       "...                ...  ...                 ...                   ...   \n",
       "3825     -1.680385e-06  ...            0.000113                178047   \n",
       "3826      1.987797e-05  ...            0.000181                232913   \n",
       "3827      3.893041e-06  ...            0.000062                105003   \n",
       "3828      1.414297e-05  ...            0.000059                200949   \n",
       "3829      6.609636e-06  ...            0.000095                165538   \n",
       "\n",
       "      total_volume_mean_200  total_volume_std_200  volume_imbalance_sum_200  \\\n",
       "0                493.568548            297.528230                     47083   \n",
       "1                552.345588            405.412262                     44587   \n",
       "2                478.143617            176.620308                     28631   \n",
       "3                655.182482            239.083336                     30554   \n",
       "4                660.990291            266.432403                     18912   \n",
       "...                     ...                   ...                       ...   \n",
       "3825             599.484848            262.821400                     91979   \n",
       "3826            1088.378505            736.848563                    113855   \n",
       "3827             656.268750            197.565138                     22315   \n",
       "3828             654.557003            304.005481                     61415   \n",
       "3829             710.463519            236.864722                     44448   \n",
       "\n",
       "      volume_imbalance_mean_200  volume_imbalance_std_200  \\\n",
       "0                    189.850806                169.815588   \n",
       "1                    327.845588                343.032789   \n",
       "2                    152.292553                118.542551   \n",
       "3                    223.021898                135.579663   \n",
       "4                    183.611650                139.040143   \n",
       "...                         ...                       ...   \n",
       "3825                 309.693603                215.491277   \n",
       "3826                 532.032710                689.228523   \n",
       "3827                 139.468750                123.093048   \n",
       "3828                 200.048860                204.854917   \n",
       "3829                 190.763948                166.924126   \n",
       "\n",
       "      bid_ask_spread_sum_200  bid_ask_spread_mean_200  bid_ask_spread_std_200  \n",
       "0                   0.117340                 0.000473                0.000345  \n",
       "1                   0.035497                 0.000261                0.000118  \n",
       "2                   0.061287                 0.000326                0.000144  \n",
       "3                   0.052588                 0.000384                0.000293  \n",
       "4                   0.030120                 0.000292                0.000147  \n",
       "...                      ...                      ...                     ...  \n",
       "3825                0.073425                 0.000247                0.000127  \n",
       "3826                0.090269                 0.000422                0.000269  \n",
       "3827                0.038521                 0.000241                0.000128  \n",
       "3828                0.089613                 0.000292                0.000119  \n",
       "3829                0.067559                 0.000290                0.000118  \n",
       "\n",
       "[3830 rows x 156 columns]"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_feature"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "af78c948",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "75ca9211",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1.000137448310852\n",
      "1.0000526905059814\n",
      "0.9999962449073792\n",
      "1.0000783205032349\n",
      "1.000166416168213\n",
      "1.0001095533370972\n",
      "1.0001587867736816\n",
      "1.0000193119049072\n",
      "1.0001413822174072\n",
      "1.0001442432403564\n",
      "1.0000419616699219\n",
      "1.000118374824524\n",
      "1.0000234842300415\n",
      "1.000003695487976\n",
      "1.0000306367874146\n",
      "1.000232219696045\n",
      "0.9999977946281433\n",
      "1.000219464302063\n",
      "1.000066876411438\n",
      "1.0000226497650146\n",
      "1.0000277757644653\n",
      "1.0000731945037842\n",
      "1.0000871419906616\n",
      "1.0000554323196411\n",
      "1.000329613685608\n",
      "1.00005304813385\n",
      "1.0000011920928955\n",
      "1.0001829862594604\n",
      "1.0000370740890503\n",
      "1.000006079673767\n",
      "1.0002317428588867\n",
      "1.000001072883606\n",
      "0.9999833106994629\n",
      "1.0000157356262207\n",
      "1.0002553462982178\n",
      "1.0001004934310913\n",
      "1.0000156164169312\n",
      "1.0000637769699097\n",
      "1.0000182390213013\n",
      "1.0000810623168945\n",
      "1.0000051259994507\n",
      "1.0000475645065308\n",
      "1.0000009536743164\n",
      "1.0000202655792236\n",
      "1.0000369548797607\n",
      "1.0000187158584595\n",
      "0.999998152256012\n",
      "1.0000135898590088\n",
      "1.000009536743164\n",
      "1.0001055002212524\n",
      "1.0000319480895996\n",
      "1.0000685453414917\n",
      "1.0000656843185425\n",
      "1.0000898838043213\n",
      "1.0000176429748535\n",
      "1.000144124031067\n",
      "1.0000427961349487\n",
      "1.000008463859558\n",
      "1.0000542402267456\n",
      "1.0000076293945312\n",
      "1.0000454187393188\n",
      "0.9999945759773254\n",
      "1.0001078844070435\n",
      "1.0000852346420288\n",
      "1.0000433921813965\n",
      "1.000015377998352\n",
      "1.0002365112304688\n",
      "1.0000054836273193\n",
      "0.9999987483024597\n",
      "1.0000944137573242\n",
      "1.000056266784668\n",
      "1.0001238584518433\n",
      "1.0000736713409424\n",
      "1.0001013278961182\n",
      "1.0000261068344116\n",
      "1.0000327825546265\n",
      "1.0000334978103638\n",
      "1.0000861883163452\n",
      "1.0001522302627563\n",
      "1.0000189542770386\n",
      "1.0001505613327026\n",
      "1.0000157356262207\n",
      "1.0001554489135742\n",
      "1.0000349283218384\n",
      "1.00005042552948\n",
      "1.0001449584960938\n",
      "1.0001589059829712\n",
      "1.0000144243240356\n",
      "1.0000722408294678\n",
      "1.0000592470169067\n",
      "1.0000680685043335\n",
      "1.0001564025878906\n",
      "1.0000503063201904\n",
      "1.000035047531128\n",
      "1.0000404119491577\n",
      "1.0000213384628296\n",
      "1.0000452995300293\n",
      "1.0000436305999756\n",
      "1.0000001192092896\n",
      "1.000148057937622\n",
      "1.0000373125076294\n",
      "1.0000725984573364\n",
      "1.0000580549240112\n",
      "1.0000903606414795\n",
      "1.0000584125518799\n",
      "0.9999794960021973\n",
      "1.0000159740447998\n",
      "1.000007152557373\n",
      "0.9999905228614807\n",
      "0.9999959468841553\n",
      "1.0000144243240356\n",
      "1.000137448310852\n"
     ]
    }
   ],
   "source": [
    "dataType = 'train'\n",
    "for stock_id in all_stock_ids:\n",
    "    dd = pd.read_parquet(os.path.join(path_data, 'book_{}.parquet/stock_id={}/'.format(dataType, stock_id)))\n",
    "    print(dd['ask_price1'].mean())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "82808387",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "time_id              16046.327585\n",
       "seconds_in_bucket      299.218141\n",
       "bid_price1               0.999995\n",
       "ask_price1               1.000023\n",
       "bid_price2               0.999975\n",
       "ask_price2               1.000042\n",
       "bid_size1              680.068224\n",
       "ask_size1              682.873746\n",
       "bid_size2              960.537840\n",
       "ask_size2              952.660925\n",
       "dtype: float64"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dd.mean()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d6ebae60",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
